﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MaxLeaf.Common;
using System.Data;
using MaxLeaf.DB;

namespace MaxLeaf.DAL
{
    public class ICDisPlyDALBuilder : BaseDALBuilder
    {


        public ICDisPlyDALBuilder()
            : base()
        {
            K3DAL = new K3.ICDisPlyDAL();

            WebDAL =   new Web.mary_icdisplyDAL();

        }
        public bool CheckHdr(ServerInfo orgServer, string strFInterID)
        {
            using (DBAccess dbOrgCon = new DBAccess(orgServer))
            {
                DataRow drOrgData = dbOrgCon.GetTableDataFirstRow("ICDisPly", new Dictionary<string, object>() { { "FInterID", strFInterID } }, "FPlyType");
                if (drOrgData == null)
                {
                    LogManager.Debug(string.Format("ICDisPly {0} not exist", strFInterID));
                    return false;
                }


                //只分发客户类别
                if (!CvtFunc.ToString(drOrgData["FPlyType"]).Equals("DisAsm4", StringComparison.InvariantCultureIgnoreCase)
                    && !CvtFunc.ToString(drOrgData["FPlyType"]).Equals("DisAsm2", StringComparison.InvariantCultureIgnoreCase)
                    )
                {

                    LogManager.Debug(string.Format("ICDisPly {0} FPlyType {1} 不分发", strFInterID, drOrgData["FPlyType"]));
                    return false;
                }

            }
            return true;
        }
        protected override bool ValidCheckOrgData(ServerInfo orgServer, DataRowView drvLog)
        {
            if (!orgServer.MasterDB)
            {
                //主账套分发
                return false;
            }

            if ((LogStatus)CvtFunc.ToInt(drvLog[DEL.LogDEL.LogStatus]) == LogStatus.Delete)
            {
                return true;
            }

            if (!CheckHdr(orgServer, CvtFunc.ToString(drvLog[DEL.LogDEL.KeyValue])))
            {
                return false;
            }

            

            return base.ValidCheckOrgData(orgServer, drvLog);
        }

        protected override bool ValidCheck(ServerInfo orgServer, ServerInfo destServer, DataRowView drvLog)
        {
            
            


            return base.ValidCheck(orgServer, destServer, drvLog);
        }


    }
}